* changes in an incompatible way, so the parser cache
* can automatically discard old data.
*/
-define( 'MW_PARSER_VERSION', '1.5.0' );
+define( 'MW_PARSER_VERSION', '1.6.0' );
/**
* Variable substitution O(N^2) attack
* performs brace substitution on MediaWiki messages
*
* Globals used:
- * objects: $wgLang, $wgLinkCache
+ * objects: $wgLang, $wgContLang
*
* NOT $wgArticle, $wgUser or $wgTitle. Keep them away!
*
var $mOutput, $mAutonumber, $mDTopen, $mStripState = array();
var $mVariables, $mIncludeCount, $mArgStack, $mLastSection, $mInPre;
var $mInterwikiLinkHolders, $mLinkHolders, $mUniqPrefix;
+ var $mTemplates, // cache of already loaded templates, avoids
+ // multiple SQL queries for the same string
+ $mTemplatePath; // stores an unsorted hash of all the templates already loaded
+ // in this path. Used for loop detection.
- # Temporary:
+ # Temporary
+ # These are variables reset at least once per parse regardless of $clearState
var $mOptions, // ParserOptions object
$mTitle, // Title context, used for self-link rendering and similar things
$mOutputType, // Output type, one of the OT_xxx constants
- $mTemplates, // cache of already loaded templates, avoids
- // multiple SQL queries for the same string
- $mTemplatePath, // stores an unsorted hash of all the templates already loaded
- // in this path. Used for loop detection.
- $mIWTransData = array(),
$mRevisionId; // ID to display in {{REVISIONID}} tags
/**#@-*/
* @access public
*/
function Parser() {
- $this->mTemplates = array();
- $this->mTemplatePath = array();
$this->mTagHooks = array();
$this->clearState();
}
$this->mRevisionId = null;
$this->mUniqPrefix = 'UNIQ' . Parser::getRandomString();
+ # Clear these on every parse, bug 4549
+ $this->mTemplates = array();
+ $this->mTemplatePath = array();
+
wfRunHooks( 'ParserClearState', array( &$this ) );
}
- /**
+ /**
+ * Accessor for mUniqPrefix.
+ *
+ * @access public
+ */
+ function UniqPrefix() {
+ return $this->mUniqPrefix;
+ }
+
+ /**
* Convert wikitext to HTML
* Do not call this function recursively.
*
* First pass--just handle <nowiki> sections, pass the rest off
* to internalParse() which does all the real work.
*/
-
- global $wgUseTidy, $wgContLang;
+
+ global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang;
$fname = 'Parser::parse';
wfProfileIn( $fname );
$this->replaceLinkHolders( $text );
- # the position of the convert() call should not be changed. it
- # assumes that the links are all replaces and the only thing left
+ # the position of the parserConvert() call should not be changed. it
+ # assumes that the links are all replaced and the only thing left
# is the <nowiki> mark.
- $text = $wgContLang->convert($text);
- $this->mOutput->setTitleText($wgContLang->getParsedTitle());
+ # Side-effects: this calls $this->mOutput->setTitleText()
+ $text = $wgContLang->parserConvert( $text, $this );
$text = $this->unstripNoWiki( $text, $this->mStripState );
wfRunHooks( 'ParserBeforeTidy', array( &$this, &$text ) );
$text = Sanitizer::normalizeCharReferences( $text );
-
- if ($wgUseTidy) {
+
+ if (($wgUseTidy and $this->mOptions->mTidy) or $wgAlwaysUseTidy) {
$text = Parser::tidy($text);
+ } else {
+ # attempt to sanitize at least some nesting problems
+ # (bug #2702 and quite a few others)
+ $tidyregs = array(
+ # ''Something [http://www.cool.com cool''] -->
+ # <i>Something</i><a href="http://www.cool.com"..><i>cool></i></a>
+ '/(<([bi])>)(<([bi])>)?([^<]*)(<\/?a[^<]*>)([^<]*)(<\/\\4>)?(<\/\\2>)/' =>
+ '\\1\\3\\5\\8\\9\\6\\1\\3\\7\\8\\9',
+ # fix up an anchor inside another anchor, only
+ # at least for a single single nested link (bug 3695)
+ '/(<a[^>]+>)([^<]*)(<a[^>]+>[^<]*)<\/a>(.*)<\/a>/' =>
+ '\\1\\2</a>\\3</a>\\1\\4</a>',
+ # fix div inside inline elements- doBlockLevels won't wrap a line which
+ # contains a div, so fix it up here; replace
+ # div with escaped text
+ '/(<([aib]) [^>]+>)([^<]*)(<div([^>]*)>)(.*)(<\/div>)([^<]*)(<\/\\2>)/' =>
+ '\\1\\3<div\\5>\\6</div>\\8\\9',
+ # remove empty italic or bold tag pairs, some
+ # introduced by rules above
+ '/<([bi])><\/\\1>/' => ''
+ );
+
+ $text = preg_replace(
+ array_keys( $tidyregs ),
+ array_values( $tidyregs ),
+ $text );
}
wfRunHooks( 'ParserAfterTidy', array( &$this, &$text ) );
return dechex(mt_rand(0, 0x7fffffff)) . dechex(mt_rand(0, 0x7fffffff));
}
+ function &getTitle() { return $this->mTitle; }
+ function getOptions() { return $this->mOptions; }
+
/**
* Replaces all occurrences of <$tag>content</$tag> in the text
* with a random marker and returns the new text. the output parameter
foreach( $gallery_content as $marker => $content ) {
require_once( 'ImageGallery.php' );
if ( $render ) {
- $gallery_content[$marker] = Parser::renderImageGallery( $content );
+ $gallery_content[$marker] = $this->renderImageGallery( $content );
} else {
$gallery_content[$marker] = '<gallery>'.$content.'</gallery>';
}
}
# Comments
- if($stripcomments) {
- $text = Parser::extractTags(STRIP_COMMENTS, $text, $comment_content, $uniq_prefix);
- foreach( $comment_content as $marker => $content ){
- $comment_content[$marker] = '<!--'.$content.'-->';
- }
+ $text = Parser::extractTags(STRIP_COMMENTS, $text, $comment_content, $uniq_prefix);
+ foreach( $comment_content as $marker => $content ){
+ $comment_content[$marker] = '<!--'.$content.'-->';
}
# Extensions
}
}
+ # Unstrip comments unless explicitly told otherwise.
+ # (The comments are always stripped prior to this point, so as to
+ # not invoke any extension tags / parser hooks contained within
+ # a comment.)
+ if ( !$stripcomments ) {
+ $tempstate = array( 'comment' => $comment_content );
+ $text = $this->unstrip( $text, $tempstate );
+ $comment_content = array();
+ }
+
# Merge state with the pre-existing state, if there is one
if ( $state ) {
$state['html'] = $state['html'] + $html_content;
$state['nowiki'] = $state['nowiki'] + $nowiki_content;
$state['math'] = $state['math'] + $math_content;
$state['pre'] = $state['pre'] + $pre_content;
- $state['comment'] = $state['comment'] + $comment_content;
$state['gallery'] = $state['gallery'] + $gallery_content;
+ $state['comment'] = $state['comment'] + $comment_content;
foreach( $ext_content as $tag => $array ) {
if ( array_key_exists( $tag, $state ) ) {
'nowiki' => $nowiki_content,
'math' => $math_content,
'pre' => $pre_content,
- 'comment' => $comment_content,
'gallery' => $gallery_content,
+ 'comment' => $comment_content,
) + $ext_content;
}
return $text;
if ( !is_array( $state ) ) {
return $text;
}
-
+
# Must expand in reverse order, otherwise nested tags will be corrupted
foreach( array_reverse( $state, true ) as $tag => $contentDict ) {
if( $tag != 'nowiki' && $tag != 'html' ) {
$pipes = array();
$process = proc_open("$wgTidyBin -config $wgTidyConf $wgTidyOpts$opts", $descriptorspec, $pipes);
if (is_resource($process)) {
+ // Theoretically, this style of communication could cause a deadlock
+ // here. If the stdout buffer fills up, then writes to stdin could
+ // block. This doesn't appear to happen with tidy, because tidy only
+ // writes to stdout after it's finished reading from stdin. Search
+ // for tidyParseStdin and tidySaveStdout in console/tidy.c
fwrite($pipes[0], $text);
fclose($pipes[0]);
while (!feof($pipes[1])) {
$ltd = array () ; # Was it TD or TH?
$tr = array () ; # Is currently a tr tag open?
$ltr = array () ; # tr attributes
+ $has_opened_tr = array(); # Did this table open a <tr> element?
$indent_level = 0; # indent level of the table
foreach ( $t AS $k => $x )
{
$fc = substr ( $x , 0 , 1 ) ;
if ( preg_match( '/^(:*)\{\|(.*)$/', $x, $matches ) ) {
$indent_level = strlen( $matches[1] );
-
+
$attributes = $this->unstripForHTML( $matches[2] );
$t[$k] = str_repeat( '<dl><dd>', $indent_level ) .
array_push ( $ltd , '' ) ;
array_push ( $tr , false ) ;
array_push ( $ltr , '' ) ;
+ array_push ( $has_opened_tr, false );
}
else if ( count ( $td ) == 0 ) { } # Don't do any of the following
else if ( '|}' == substr ( $x , 0 , 2 ) ) {
$z = "</table>" . substr ( $x , 2);
$l = array_pop ( $ltd ) ;
+ if ( !array_pop ( $has_opened_tr ) ) $z = "<tr><td></td></tr>" . $z ;
if ( array_pop ( $tr ) ) $z = '</tr>' . $z ;
if ( array_pop ( $td ) ) $z = '</'.$l.'>' . $z ;
array_pop ( $ltr ) ;
while ( $x != '' && substr ( $x , 0 , 1 ) == '-' ) $x = substr ( $x , 1 ) ;
$z = '' ;
$l = array_pop ( $ltd ) ;
+ array_pop ( $has_opened_tr );
+ array_push ( $has_opened_tr , true ) ;
if ( array_pop ( $tr ) ) $z = '</tr>' . $z ;
if ( array_pop ( $td ) ) $z = '</'.$l.'>' . $z ;
array_pop ( $ltr ) ;
if ( !array_pop ( $tr ) ) $z = '<tr'.$tra.">\n" ;
array_push ( $tr , true ) ;
array_push ( $ltr , '' ) ;
+ array_pop ( $has_opened_tr );
+ array_push ( $has_opened_tr , true ) ;
}
$l = array_pop ( $ltd ) ;
# Closing open td, tr && table
while ( count ( $td ) > 0 )
{
+ $l = array_pop ( $ltd ) ;
if ( array_pop ( $td ) ) $t[] = '</td>' ;
if ( array_pop ( $tr ) ) $t[] = '</tr>' ;
+ if ( !array_pop ( $has_opened_tr ) ) $t[] = "<tr><td></td></tr>" ;
$t[] = '</table>' ;
}
$t = implode ( "\n" , $t ) ;
+ # special case: don't return empty table
+ if($t == "<table>\n<tr><td></td></tr>\n</table>")
+ $t = '';
wfProfileOut( $fname );
return $t ;
}
* @access private
*/
function internalParse( $text ) {
- global $wgContLang;
$args = array();
$isMain = true;
$fname = 'Parser::internalParse';
$text = $this->doTableStuff( $text );
$text = $this->formatHeadings( $text, $isMain );
- $regex = '/<!--IW_TRANSCLUDE (\d+)-->/';
- $text = preg_replace_callback($regex, array(&$this, 'scarySubstitution'), $text);
-
wfProfileOut( $fname );
return $text;
}
- function scarySubstitution($matches) {
-# return "[[".$matches[0]."]]";
- return $this->mIWTransData[(int)$matches[0]];
- }
-
/**
* Replace special strings like "ISBN xxx" and "RFC xxx" with
* magic external links.
# Replace & from obsolete syntax with &.
# All HTML entities will be escaped by makeExternalLink()
- # or maybeMakeExternalImage()
$url = str_replace( '&', '&', $url );
# Process the trail (i.e. everything after this link up until start of the next link),
# replacing any non-bracketed links
$trail = $this->replaceFreeExternalLinks( $trail );
-
# Use the encoded URL
# This means that users can paste URLs directly into the text
# Funny characters like ö aren't valid in URLs anyway
# This was changed in August 2004
$s .= $sk->makeExternalLink( $url, $text, false, $linktype ) . $dtrail . $trail;
+
+ # Register link in the output object.
+ # Replace unnecessary URL escape codes with the referenced character
+ # This prevents spammers from hiding links from the filters
+ $pasteurized = Parser::replaceUnusualEscapes( $url );
+ $this->mOutput->addExternalLink( $pasteurized );
}
wfProfileOut( $fname );
$url = $protocol . $m[1];
$trail = $m[2];
+ # special case: handle urls as url args:
+ # http://www.example.com/foo?=http://www.example.com/bar
+ if(strlen($trail) == 0 &&
+ isset($bits[$i]) &&
+ preg_match('/^'. wfUrlProtocols() . '$/S', $bits[$i]) &&
+ preg_match( '/^('.EXT_LINK_URL_CLASS.'+)(.*)$/s', $bits[$i + 1], $m ))
+ {
+ # add protocol, arg
+ $url .= $bits[$i] . $bits[$i + 1]; # protocol, url as arg to previous link
+ $i += 2;
+ $trail = $m[2];
+ }
+
# The characters '<' and '>' (which were escaped by
# removeHTMLtags()) should not be included in
# URLs, per RFC 2396.
if ( $text === false ) {
# Not an image, make a link
$text = $sk->makeExternalLink( $url, $wgContLang->markNoConversion($url), true, 'free' );
+ # Register it in the output object...
+ # Replace unnecessary URL escape codes with their equivalent characters
+ $pasteurized = Parser::replaceUnusualEscapes( $url );
+ $this->mOutput->addExternalLink( $pasteurized );
}
$s .= $text . $trail;
} else {
return $s;
}
+ /**
+ * Replace unusual URL escape codes with their equivalent characters
+ * @param string
+ * @return string
+ * @static
+ * @fixme This can merge genuinely required bits in the path or query string,
+ * breaking legit URLs. A proper fix would treat the various parts of
+ * the URL differently; as a workaround, just use the output for
+ * statistical records, not for actual linking/output.
+ */
+ function replaceUnusualEscapes( $url ) {
+ return preg_replace_callback( '/%[0-9A-Fa-f]{2}/',
+ array( 'Parser', 'replaceUnusualEscapesCallback' ), $url );
+ }
+
+ /**
+ * Callback function used in replaceUnusualEscapes().
+ * Replaces unusual URL escape codes with their equivalent character
+ * @static
+ * @access private
+ */
+ function replaceUnusualEscapesCallback( $matches ) {
+ $char = urldecode( $matches[0] );
+ $ord = ord( $char );
+ // Is it an unsafe or HTTP reserved character according to RFC 1738?
+ if ( $ord > 32 && $ord < 127 && strpos( '<>"#{}|\^~[]`;/?', $char ) === false ) {
+ // No, shouldn't be escaped
+ return $char;
+ } else {
+ // Yes, leave it escaped
+ return $matches[0];
+ }
+ }
+
/**
* make an image if it's allowed, either through the global
* option or through the exception
$imagesfrom = $this->mOptions->getAllowExternalImagesFrom();
$imagesexception = !empty($imagesfrom);
$text = false;
- if ( $this->mOptions->getAllowExternalImages()
+ if ( $this->mOptions->getAllowExternalImages()
|| ( $imagesexception && strpos( $url, $imagesfrom ) === 0 ) ) {
if ( preg_match( EXT_IMAGE_REGEX, $url ) ) {
# Image found
* @access private
*/
function replaceInternalLinks( $s ) {
- global $wgContLang, $wgLinkCache;
+ global $wgContLang;
static $fname = 'Parser::replaceInternalLinks' ;
wfProfileIn( $fname );
# Still some problems for cases where the ] is meant to be outside punctuation,
# and no image is in sight. See bug 2095.
#
- if( $text !== '' && preg_match( "/^\](.*)/s", $m[3], $n ) ) {
+ if( $text !== '' &&
+ preg_match( "/^\](.*)/s", $m[3], $n ) &&
+ strpos($text, '[') !== false
+ )
+ {
$text .= ']'; # so that replaceExternalLinks($text) works later
$m[3] = $n[1];
}
# fix up urlencoded title texts
- if(preg_match('/%/', $m[1] )) $m[1] = urldecode($m[1]);
+ if(preg_match('/%/', $m[1] ))
+ # Should anchors '#' also be rejected?
+ $m[1] = str_replace( array('<', '>'), array('<', '>'), urldecode($m[1]) );
$trail = $m[3];
} elseif( preg_match($e1_img, $line, $m) ) { # Invalid, but might be an image with a link in its caption
$might_be_img = true;
# cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
$s .= $prefix . $this->armorLinks( $this->makeImage( $nt, $text ) ) . $trail;
- $this->mOutput->addImage( $nt->getDBkey() );
+ $this->mOutput->addImage( $nt->getDBkey() );
wfProfileOut( "$fname-image" );
continue;
}
return $retVal;
}
-
+
/**
* Render a forced-blue link inline; protect against double expansion of
* URLs if we're in a mode that prepends full URL prefixes to internal links.
$link = $sk->makeKnownLinkObj( $nt, $text, $query, $inside, $prefix );
return $this->armorLinks( $link ) . $trail;
}
-
+
/**
* Insert a NOPARSE hacky thing into any inline links in a chunk that's
* going to go through further parsing steps before inline URL expansion.
return $varCache[$index] = $wgContLang->getMonthAbbreviation( date( 'n', $ts ) );
case MAG_CURRENTDAY:
return $varCache[$index] = $wgContLang->formatNum( date( 'j', $ts ) );
+ case MAG_CURRENTDAY2:
+ return $varCache[$index] = $wgContLang->formatNum( date( 'd', $ts ) );
case MAG_PAGENAME:
return $this->mTitle->getText();
case MAG_PAGENAMEE:
case MAG_FULLPAGENAME:
return $this->mTitle->getPrefixedText();
case MAG_FULLPAGENAMEE:
- return wfUrlencode( $this->mTitle->getPrefixedText() );
+ return $this->mTitle->getPrefixedURL();
+ case MAG_SUBPAGENAME:
+ return $this->mTitle->getSubpageText();
case MAG_REVISIONID:
return $this->mRevisionId;
case MAG_NAMESPACE:
case MAG_CURRENTTIME:
return $varCache[$index] = $wgContLang->time( wfTimestamp( TS_MW, $ts ), false, false );
case MAG_CURRENTWEEK:
- return $varCache[$index] = $wgContLang->formatNum( date( 'W', $ts ) );
+ // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
+ // int to remove the padding
+ return $varCache[$index] = $wgContLang->formatNum( (int)date( 'W', $ts ) );
case MAG_CURRENTDOW:
return $varCache[$index] = $wgContLang->formatNum( date( 'w', $ts ) );
case MAG_NUMBEROFARTICLES:
if ($lastOpeningBrace >= 0) {
$pos = strpos ($text, $openingBraceStack[$lastOpeningBrace]['braceEnd'], $i);
-
+
if (false !== $pos && (-1 == $nextPos || $pos < $nextPos)){
$rule = null;
$nextPos = $pos;
}
$pos = strpos ($text, '|', $i);
-
+
if (false !== $pos && (-1 == $nextPos || $pos < $nextPos)){
$rule = null;
$nextPos = $pos;
'title' => '',
'parts' => null);
- # count openning brace characters
+ # count openning brace characters
while ($i+1 < strlen($text) && $text[$i+1] == $piece['brace']) {
$piece['count']++;
$i++;
}
- $piece['startAt'] = $i+1;
- $piece['partStart'] = $i+1;
+ $piece['startAt'] = $i+1;
+ $piece['partStart'] = $i+1;
# we need to add to stack only if openning brace count is enough for any given rule
foreach ($rule['cb'] as $cnt => $fn) {
$matchingCallback = $fn;
}
}
-
+
if ($matchingCount == 0) {
$i += $count - 1;
continue;
$pieceStart = $openingBraceStack[$lastOpeningBrace]['startAt'] - $matchingCount;
$pieceEnd = $i + $matchingCount;
-
+
if( is_callable( $matchingCallback ) ) {
$cbArgs = array (
'text' => substr($text, $pieceStart, $pieceEnd - $pieceStart),
}
else
$openingBraceStack[$lastOpeningBrace]['parts'][] = substr($text, $openingBraceStack[$lastOpeningBrace]['partStart'], $i - $openingBraceStack[$lastOpeningBrace]['partStart']);
-
+
$openingBraceStack[$lastOpeningBrace]['partStart'] = $i + 1;
}
}
*
* @param string $tex The text to transform
* @param array $args Key-value pairs representing template parameters to substitute
+ * @param bool $argsOnly Only do argument (triple-brace) expansion, not double-brace expansion
* @access private
*/
- function replaceVariables( $text, $args = array() ) {
+ function replaceVariables( $text, $args = array(), $argsOnly = false ) {
# Prevent too big inclusions
if( strlen( $text ) > MAX_INCLUDE_SIZE ) {
return $text;
array_push( $this->mArgStack, $args );
$braceCallbacks = array();
- $braceCallbacks[2] = array( &$this, 'braceSubstitution' );
+ if ( !$argsOnly ) {
+ $braceCallbacks[2] = array( &$this, 'braceSubstitution' );
+ }
if ( $this->mOutputType == OT_HTML || $this->mOutputType == OT_WIKI ) {
$braceCallbacks[3] = array( &$this, 'argSubstitution' );
}
$fname = 'Parser::braceSubstitution';
wfProfileIn( $fname );
- $found = false;
- $nowiki = false;
- $noparse = false;
+ # Flags
+ $found = false; # $text has been filled
+ $nowiki = false; # wiki markup in $text should be escaped
+ $noparse = false; # Unsafe HTML tags should not be stripped, etc.
+ $noargs = false; # Don't replace triple-brace arguments in $text
+ $replaceHeadings = false; # Make the edit section links go to the template not the article
+ $isHTML = false; # $text is HTML, armour it against wikitext transformation
+ $forceRawInterwiki = false; # Force interwiki transclusion to be done in raw mode not rendered
+ # Title object, where $text came from
$title = NULL;
$linestart = '';
$text = $replaceWith;
$found = true;
$noparse = true;
+ $noargs = true;
}
}
$text = $piece['text'];
$found = true;
$noparse = true;
+ $noargs = true;
}
}
- # MSG, MSGNW and INT
+ # MSG, MSGNW, INT and RAW
if ( !$found ) {
# Check for MSGNW:
$mwMsgnw =& MagicWord::get( MAG_MSGNW );
$mwMsg =& MagicWord::get( MAG_MSG );
$mwMsg->matchStartAndRemove( $part1 );
}
-
+
+ # Check for RAW:
+ $mwRaw =& MagicWord::get( MAG_RAW );
+ if ( $mwRaw->matchStartAndRemove( $part1 ) ) {
+ $forceRawInterwiki = true;
+ }
+
# Check if it is an internal message
$mwInt =& MagicWord::get( MAG_INT );
if ( $mwInt->matchStartAndRemove( $part1 ) ) {
# Check for NS: (namespace expansion)
$mwNs = MagicWord::get( MAG_NS );
if ( $mwNs->matchStartAndRemove( $part1 ) ) {
- if ( intval( $part1 ) ) {
+ if ( intval( $part1 ) || $part1 == "0" ) {
$text = $linestart . $wgContLang->getNsText( intval( $part1 ) );
$found = true;
} else {
$mwLocalE =& MagicWord::get( MAG_LOCALURLE );
$mwFull =& MagicWord::get( MAG_FULLURL );
$mwFullE =& MagicWord::get( MAG_FULLURLE );
-
+
if ( $mwLocal->matchStartAndRemove( $part1 ) ) {
$func = 'getLocalURL';
# Did we encounter this template already? If yes, it is in the cache
# and we need to check for loops.
- if ( !$found && isset( $this->mTemplates[$part1] ) ) {
+ if ( !$found && isset( $this->mTemplates[$piece['title']] ) ) {
$found = true;
# Infinite loop test
if ( isset( $this->mTemplatePath[$part1] ) ) {
$noparse = true;
+ $noargs = true;
$found = true;
$text = $linestart .
'{{' . $part1 . '}}' .
wfDebug( "$fname: template loop broken at '$part1'\n" );
} else {
# set $text to cached message.
- $text = $linestart . $this->mTemplates[$part1];
+ $text = $linestart . $this->mTemplates[$piece['title']];
}
}
# Load from database
- $replaceHeadings = false;
- $isHTML = false;
$lastPathLevel = $this->mTemplatePath;
if ( !$found ) {
$ns = NS_TEMPLATE;
- $part1 = $this->maybeDoSubpageLink( $part1, $subpage='' );
+ # declaring $subpage directly in the function call
+ # does not work correctly with references and breaks
+ # {{/subpage}}-style inclusions
+ $subpage = '';
+ $part1 = $this->maybeDoSubpageLink( $part1, $subpage );
if ($subpage !== '') {
$ns = $this->mTitle->getNamespace();
}
$title = Title::newFromText( $part1, $ns );
- if ($title) {
- $interwiki = Title::getInterwikiLink($title->getInterwiki());
- if ($interwiki != '' && $title->isTrans()) {
- return $this->scarytransclude($title, $interwiki);
- }
- }
-
- if ( !is_null( $title ) && !$title->isExternal() ) {
- # Check for excessive inclusion
- $dbk = $title->getPrefixedDBkey();
- if ( $this->incrementIncludeCount( $dbk ) ) {
- if ( $title->getNamespace() == NS_SPECIAL && $this->mOptions->getAllowSpecialInclusion() ) {
- # Capture special page output
- $text = SpecialPage::capturePath( $title );
- if ( is_string( $text ) ) {
- $found = true;
- $noparse = true;
- $isHTML = true;
- $this->disableCache();
- }
- } else {
- $article = new Article( $title );
- $articleContent = $article->fetchContent(0, false);
- if ( $articleContent !== false ) {
- $found = true;
- $text = $articleContent;
- $replaceHeadings = true;
+ if ( !is_null( $title ) ) {
+ if ( !$title->isExternal() ) {
+ # Check for excessive inclusion
+ $dbk = $title->getPrefixedDBkey();
+ if ( $this->incrementIncludeCount( $dbk ) ) {
+ if ( $title->getNamespace() == NS_SPECIAL && $this->mOptions->getAllowSpecialInclusion() ) {
+ # Capture special page output
+ $text = SpecialPage::capturePath( $title );
+ if ( is_string( $text ) ) {
+ $found = true;
+ $noparse = true;
+ $noargs = true;
+ $isHTML = true;
+ $this->disableCache();
+ }
+ } else {
+ $articleContent = $this->fetchTemplate( $title );
+ if ( $articleContent !== false ) {
+ $found = true;
+ $text = $articleContent;
+ $replaceHeadings = true;
+ }
}
- # Register a template reference whether or not the template exists
- $this->mOutput->addTemplate( $title->getNamespace(), $title->getDBkey(),
- $article->getID() );
}
- }
- # If the title is valid but undisplayable, make a link to it
- if ( $this->mOutputType == OT_HTML && !$found ) {
- $text = '[['.$title->getPrefixedText().']]';
+ # If the title is valid but undisplayable, make a link to it
+ if ( $this->mOutputType == OT_HTML && !$found ) {
+ $text = '[['.$title->getPrefixedText().']]';
+ $found = true;
+ }
+ } elseif ( $title->isTrans() ) {
+ // Interwiki transclusion
+ if ( $this->mOutputType == OT_HTML && !$forceRawInterwiki ) {
+ $text = $this->interwikiTransclude( $title, 'render' );
+ $isHTML = true;
+ $noparse = true;
+ } else {
+ $text = $this->interwikiTransclude( $title, 'raw' );
+ $replaceHeadings = true;
+ }
$found = true;
}
-
+
# Template cache array insertion
+ # Use the original $piece['title'] not the mangled $part1, so that
+ # modifiers such as RAW: produce separate cache entries
if( $found ) {
- $this->mTemplates[$part1] = $text;
+ $this->mTemplates[$piece['title']] = $text;
$text = $linestart . $text;
}
}
# Only for HTML output
if ( $nowiki && $found && $this->mOutputType == OT_HTML ) {
$text = wfEscapeWikiText( $text );
- } elseif ( ($this->mOutputType == OT_HTML || $this->mOutputType == OT_WIKI) && $found && !$noparse) {
- # Clean up argument array
- $assocArgs = array();
- $index = 1;
- foreach( $args as $arg ) {
- $eqpos = strpos( $arg, '=' );
- if ( $eqpos === false ) {
- $assocArgs[$index++] = $arg;
- } else {
- $name = trim( substr( $arg, 0, $eqpos ) );
- $value = trim( substr( $arg, $eqpos+1 ) );
- if ( $value === false ) {
- $value = '';
- }
- if ( $name !== false ) {
- $assocArgs[$name] = $value;
+ } elseif ( ($this->mOutputType == OT_HTML || $this->mOutputType == OT_WIKI) && $found ) {
+ if ( !$noargs ) {
+ # Clean up argument array
+ $assocArgs = array();
+ $index = 1;
+ foreach( $args as $arg ) {
+ $eqpos = strpos( $arg, '=' );
+ if ( $eqpos === false ) {
+ $assocArgs[$index++] = $arg;
+ } else {
+ $name = trim( substr( $arg, 0, $eqpos ) );
+ $value = trim( substr( $arg, $eqpos+1 ) );
+ if ( $value === false ) {
+ $value = '';
+ }
+ if ( $name !== false ) {
+ $assocArgs[$name] = $value;
+ }
}
}
- }
- # Add a new element to the templace recursion path
- $this->mTemplatePath[$part1] = 1;
-
- # If there are any <onlyinclude> tags, only include them
- if ( in_string( '<onlyinclude>', $text ) && in_string( '</onlyinclude>', $text ) ) {
- preg_match_all( '/<onlyinclude>(.*?)\n?<\/onlyinclude>/s', $text, $m );
- $text = '';
- foreach ($m[1] as $piece)
- $text .= $piece;
- }
- # Remove <noinclude> sections and <includeonly> tags
- $text = preg_replace( '/<noinclude>.*?<\/noinclude>/s', '', $text );
- $text = strtr( $text, array( '<includeonly>' => '' , '</includeonly>' => '' ) );
-
- if( $this->mOutputType == OT_HTML ) {
- # Strip <nowiki>, <pre>, etc.
- $text = $this->strip( $text, $this->mStripState );
- $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'replaceVariables' ), $assocArgs );
+ # Add a new element to the templace recursion path
+ $this->mTemplatePath[$part1] = 1;
}
- $text = $this->replaceVariables( $text, $assocArgs );
- # If the template begins with a table or block-level
- # element, it should be treated as beginning a new line.
- if (!$piece['lineStart'] && preg_match('/^({\\||:|;|#|\*)/', $text)) {
- $text = "\n" . $text;
+ if ( !$noparse ) {
+ # If there are any <onlyinclude> tags, only include them
+ if ( in_string( '<onlyinclude>', $text ) && in_string( '</onlyinclude>', $text ) ) {
+ preg_match_all( '/<onlyinclude>(.*?)\n?<\/onlyinclude>/s', $text, $m );
+ $text = '';
+ foreach ($m[1] as $piece)
+ $text .= $piece;
+ }
+ # Remove <noinclude> sections and <includeonly> tags
+ $text = preg_replace( '/<noinclude>.*?<\/noinclude>/s', '', $text );
+ $text = strtr( $text, array( '<includeonly>' => '' , '</includeonly>' => '' ) );
+
+ if( $this->mOutputType == OT_HTML ) {
+ # Strip <nowiki>, <pre>, etc.
+ $text = $this->strip( $text, $this->mStripState );
+ $text = Sanitizer::removeHTMLtags( $text, array( &$this, 'replaceVariables' ), $assocArgs );
+ }
+ $text = $this->replaceVariables( $text, $assocArgs );
+
+ # If the template begins with a table or block-level
+ # element, it should be treated as beginning a new line.
+ if (!$piece['lineStart'] && preg_match('/^({\\||:|;|#|\*)/', $text)) {
+ $text = "\n" . $text;
+ }
+ } elseif ( !$noargs ) {
+ # $noparse and !$noargs
+ # Just replace the arguments, not any double-brace items
+ # This is used for rendered interwiki transclusion
+ $text = $this->replaceVariables( $text, $assocArgs, true );
}
}
# Prune lower levels off the recursion check path
return $text;
}
}
-
+
+ /**
+ * Fetch the unparsed text of a template and register a reference to it.
+ */
+ function fetchTemplate( $title ) {
+ $text = false;
+ // Loop to fetch the article, with up to 1 redirect
+ for ( $i = 0; $i < 2 && is_object( $title ); $i++ ) {
+ $rev = Revision::newFromTitle( $title );
+ $this->mOutput->addTemplate( $title, $title->getArticleID() );
+ if ( !$rev ) {
+ break;
+ }
+ $text = $rev->getText();
+ if ( $text === false ) {
+ break;
+ }
+ // Redirect?
+ $title = Title::newFromRedirect( $text );
+ }
+ return $text;
+ }
+
/**
- * Translude an interwiki link.
+ * Transclude an interwiki link.
*/
- function scarytransclude($title, $interwiki) {
- global $wgEnableScaryTranscluding;
+ function interwikiTransclude( $title, $action ) {
+ global $wgEnableScaryTranscluding, $wgCanonicalNamespaceNames;
if (!$wgEnableScaryTranscluding)
return wfMsg('scarytranscludedisabled');
- $articlename = "Template:" . $title->getDBkey();
- $url = str_replace('$1', urlencode($articlename), $interwiki);
+ // The namespace will actually only be 0 or 10, depending on whether there was a leading :
+ // But we'll handle it generally anyway
+ if ( $title->getNamespace() ) {
+ // Use the canonical namespace, which should work anywhere
+ $articleName = $wgCanonicalNamespaceNames[$title->getNamespace()] . ':' . $title->getDBkey();
+ } else {
+ $articleName = $title->getDBkey();
+ }
+
+ $url = str_replace('$1', urlencode($articleName), Title::getInterwikiLink($title->getInterwiki()));
+ $url .= "?action=$action";
if (strlen($url) > 255)
return wfMsg('scarytranscludetoolong');
- $text = $this->fetchScaryTemplateMaybeFromCache($url);
- $this->mIWTransData[] = $text;
- return "<!--IW_TRANSCLUDE ".(count($this->mIWTransData) - 1)."-->";
+ return $this->fetchScaryTemplateMaybeFromCache($url);
}
function fetchScaryTemplateMaybeFromCache($url) {
+ global $wgTranscludeCacheExpiry;
$dbr =& wfGetDB(DB_SLAVE);
$obj = $dbr->selectRow('transcache', array('tc_time', 'tc_contents'),
array('tc_url' => $url));
if ($obj) {
$time = $obj->tc_time;
$text = $obj->tc_contents;
- if ($time && $time < (time() + (60*60))) {
+ if ($time && time() < $time + $wgTranscludeCacheExpiry ) {
return $text;
}
}
- $text = wfGetHTTP($url . '?action=render');
+ $text = wfGetHTTP($url);
if (!$text)
return wfMsg('scarytranscludefailed', $url);
$dbw =& wfGetDB(DB_MASTER);
- $dbw->replace('transcache', array(), array(
+ $dbw->replace('transcache', array('tc_url'), array(
'tc_url' => $url,
'tc_time' => time(),
'tc_contents' => $text));
# strip out HTML
$canonized_headline = preg_replace( '/<.*?' . '>/','',$canonized_headline );
$tocline = trim( $canonized_headline );
- $canonized_headline = urlencode( Sanitizer::decodeCharReferences( str_replace(' ', '_', $tocline) ) );
- $replacearray = array(
- '%3A' => ':',
- '%' => '.'
- );
- $canonized_headline = str_replace(array_keys($replacearray),array_values($replacearray),$canonized_headline);
+ # Save headline for section edit hint before it's escaped
+ $headline_hint = trim( $canonized_headline );
+ $canonized_headline = Sanitizer::escapeId( $tocline );
$refers[$headlineCount] = $canonized_headline;
# count how many in assoc. array so we can track dupes in anchors
if( $istemplate )
$head[$headlineCount] .= $sk->editSectionLinkForOther($templatetitle, $templatesection);
else
- $head[$headlineCount] .= $sk->editSectionLink($this->mTitle, $sectionCount+1);
+ $head[$headlineCount] .= $sk->editSectionLink($this->mTitle, $sectionCount+1, $headline_hint);
}
# give headline the correct <h#> tag
$valid = '0123456789-Xx';
foreach ( $a as $x ) {
+ # hack: don't replace inside thumbnail title/alt
+ # attributes
+ if(preg_match('/<[^>]+(alt|title)="[^">]*$/', $text)) {
+ $text .= "ISBN $x";
+ continue;
+ }
+
$isbn = $blank = '' ;
while ( ' ' == $x{0} ) {
$blank .= ' ';
} else {
$titleObj = Title::makeTitle( NS_SPECIAL, 'Booksources' );
$text .= '<a href="' .
- $titleObj->escapeLocalUrl( 'isbn='.$num ) .
+ $titleObj->escapeLocalUrl( 'isbn='.$num ) .
"\" class=\"internal\">ISBN $isbn</a>";
$text .= $x;
}
continue;
}
+ # hack: don't replace inside thumbnail title/alt
+ # attributes
+ if(preg_match('/<[^>]+(alt|title)="[^">]*$/', $text)) {
+ $text .= $keyword . $x;
+ continue;
+ }
+
$id = $blank = '' ;
/** remove and save whitespaces in $blank */
function pstPass2( $text, &$user ) {
global $wgContLang, $wgLocaltimezone;
- # Variable replacement
- # Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags
- $text = $this->replaceVariables( $text );
-
- # Signatures
- #
- $sigText = $this->getUserSig( $user );
-
/* Note: This is the timestamp saved as hardcoded wikitext to
* the database, we use $wgContLang here in order to give
* everyone the same signiture and use the default one rather
putenv( 'TZ='.$oldtz );
}
- $text = preg_replace( '/~~~~~/', $d, $text );
- $text = preg_replace( '/~~~~/', "$sigText $d", $text );
- $text = preg_replace( '/~~~/', $sigText, $text );
+ # Variable replacement
+ # Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags
+ $text = $this->replaceVariables( $text );
+
+ # Signatures
+ $sigText = $this->getUserSig( $user );
+ $text = strtr( $text, array(
+ '~~~~~' => $d,
+ '~~~~' => "$sigText $d",
+ '~~~' => $sigText
+ ) );
# Context links: [[|name]] and [[name (context)|]]
#
global $wgLegalTitleChars;
$tc = "[$wgLegalTitleChars]";
$np = str_replace( array( '(', ')' ), array( '', '' ), $tc ); # No parens
-
+
$namespacechar = '[ _0-9A-Za-z\x80-\xff]'; # Namespaces can use non-ascii!
$conpat = "/^({$np}+) \\(({$tc}+)\\)$/";
return $text;
}
-
+
/**
* Fetch the user's signature text, if any, and normalize to
* validated, ready-to-insert wikitext.
* @access private
*/
function getUserSig( &$user ) {
- $name = $user->getName();
- $nick = trim( $user->getOption( 'nickname' ) );
- if ( '' == $nick ) {
- $nick = $name;
- }
-
- if( $user->getOption( 'fancysig' ) ) {
- // A wikitext signature.
- $valid = $this->validateSig( $nick );
- if( $valid === false ) {
- // Fall back to default sig
- $nick = $name;
- wfDebug( "Parser::getUserSig: $name has bad XML tags in signature.\n" );
+ $username = $user->getName();
+ $nickname = $user->getOption( 'nickname' );
+ $nickname = $nickname === '' ? $username : $nickname;
+
+ if( $user->getBoolOption( 'fancysig' ) !== false ) {
+ # Sig. might contain markup; validate this
+ if( $this->validateSig( $nickname ) !== false ) {
+ # Validated; clean up (if needed) and return it
+ return( $this->cleanSig( $nickname ) );
} else {
- return $nick;
+ # Failed to validate; fall back to the default
+ $nickname = $username;
+ wfDebug( "Parser::getUserSig: $username has bad XML tags in signature.\n" );
}
}
-
- // Plain text linking to the user's homepage
- global $wgContLang;
- $page = $user->getUserPage();
- return '[[' .
- $page->getPrefixedText() .
- "|" .
- wfEscapeWikIText( $nick ) .
- "]]";
+
+ # If we're still here, make it a link to the user page
+ $userpage = $user->getUserPage();
+ return( '[[' . $userpage->getPrefixedText() . '|' . wfEscapeWikiText( $nickname ) . ']]' );
}
-
+
/**
- * We want to enforce two rules on wikitext sigs here:
- * 1) Expand any templates at save time (forced subst:)
- * 2) Check for unbalanced XML tags, and reject if so.
+ * Check that the user's signature contains no bad XML
*
* @param string $text
* @return mixed An expanded string, or false if invalid.
- *
- * @todo Run brace substitutions
- * @todo ?? Check for unbalanced '' and ''' quotes, etc
*/
function validateSig( $text ) {
- if( wfIsWellFormedXmlFragment( $text ) ) {
- return $text;
- } else {
- return false;
- }
+ return( wfIsWellFormedXmlFragment( $text ) ? $text : false );
}
+
+ /**
+ * Clean up signature text
+ *
+ * 1) Strip ~~~, ~~~~ and ~~~~~ out of signatures
+ * 2) Substitute all transclusions
+ *
+ * @param string $text
+ * @return string Signature text
+ */
+ function cleanSig( $text ) {
+ $substWord = MagicWord::get( MAG_SUBST );
+ $substRegex = '/\{\{(?!(?:' . $substWord->getBaseRegex() . '))/x' . $substWord->getRegexCase();
+ $substText = '{{' . $substWord->getSynonym( 0 );
+ $text = preg_replace( $substRegex, $substText, $text );
+ $text = preg_replace( '/~{3,5}/', '', $text );
+ $text = $this->replaceVariables( $text );
+
+ return $text;
+ }
+
/**
* Set up some variables which are usually set up in parse()
* so that an external function can call some class members with confidence
global $wgTitle;
static $executing = false;
+ $fname = "Parser::transformMsg";
+
# Guard against infinite recursion
if ( $executing ) {
return $text;
}
$executing = true;
+ wfProfileIn($fname);
+
$this->mTitle = $wgTitle;
$this->mOptions = $options;
$this->mOutputType = OT_MSG;
$text = $this->replaceVariables( $text );
$executing = false;
+ wfProfileOut($fname);
return $text;
}
/**
* Create an HTML-style tag, e.g. <yourtag>special text</yourtag>
- * Callback will be called with the text within
- * Transform and return the text within
+ * The callback should have the following form:
+ * function myParserHook( $text, $params, &$parser ) { ... }
+ *
+ * Transform and return $text. Use $parser for any required context, e.g. use
+ * $parser->getTitle() and $parser->getOptions() not $wgTitle or $wgOut->mParserOptions
*
* @access public
*
function setHook( $tag, $callback ) {
$oldVal = @$this->mTagHooks[$tag];
$this->mTagHooks[$tag] = $callback;
-
+
return $oldVal;
}
* $options is a bit field, RLH_FOR_UPDATE to select for update
*/
function replaceLinkHolders( &$text, $options = 0 ) {
- global $wgUser, $wgLinkCache;
+ global $wgUser;
global $wgOutputReplace;
$fname = 'Parser::replaceLinkHolders';
$pdbks = array();
$colours = array();
- $sk = $this->mOptions->getSkin();
+ $sk =& $this->mOptions->getSkin();
+ $linkCache =& LinkCache::singleton();
if ( !empty( $this->mLinkHolders['namespaces'] ) ) {
wfProfileIn( $fname.'-check' );
# Check if it's a static known link, e.g. interwiki
if ( $title->isAlwaysKnown() ) {
$colours[$pdbk] = 1;
- } elseif ( ( $id = $wgLinkCache->getGoodLinkID( $pdbk ) ) != 0 ) {
+ } elseif ( ( $id = $linkCache->getGoodLinkID( $pdbk ) ) != 0 ) {
$colours[$pdbk] = 1;
- $this->mOutput->addLink( $ns, $this->mLinkHolders['dbkeys'][$key], $id );
- } elseif ( $wgLinkCache->isBadLink( $pdbk ) ) {
+ $this->mOutput->addLink( $title, $id );
+ } elseif ( $linkCache->isBadLink( $pdbk ) ) {
$colours[$pdbk] = 0;
} else {
# Not in the link cache, add it to the query
while ( $s = $dbr->fetchObject($res) ) {
$title = Title::makeTitle( $s->page_namespace, $s->page_title );
$pdbk = $title->getPrefixedDBkey();
- $wgLinkCache->addGoodLinkObj( $s->page_id, $title );
- $this->mOutput->addLink( $s->page_namespace, $s->page_title, $s->page_id );
+ $linkCache->addGoodLinkObj( $s->page_id, $title );
+ $this->mOutput->addLink( $title, $s->page_id );
if ( $threshold > 0 ) {
$size = $s->page_len;
$searchkey = "<!--LINK $key-->";
$title = $this->mLinkHolders['titles'][$key];
if ( empty( $colours[$pdbk] ) ) {
- $wgLinkCache->addBadLinkObj( $title );
+ $linkCache->addBadLinkObj( $title );
$colours[$pdbk] = 0;
- $this->mOutput->addLink( $ns, $this->mLinkHolders['dbkeys'][$key], 0 );
+ $this->mOutput->addLink( $title, 0 );
$wgOutputReplace[$searchkey] = $sk->makeBrokenLinkObj( $title,
$this->mLinkHolders['texts'][$key],
$this->mLinkHolders['queries'][$key] );
* @return string
*/
function replaceLinkHoldersText( $text ) {
- global $wgUser;
- global $wgOutputReplace;
-
$fname = 'Parser::replaceLinkHoldersText';
wfProfileIn( $fname );
* given as text will return the HTML of a gallery with two images,
* labeled 'The number "1"' and
* 'A tree'.
- *
- * @static
*/
function renderImageGallery( $text ) {
# Setup the parser
- global $wgTitle;
$parserOptions = new ParserOptions;
$localParser = new Parser();
if ( count( $matches ) == 0 ) {
continue;
}
- $nt = Title::newFromURL( $matches[1] );
+ $nt =& Title::newFromText( $matches[1] );
if( is_null( $nt ) ) {
# Bogus title. Ignore these so we don't bomb out later.
continue;
$label = '';
}
- $html = $localParser->parse( $label , $wgTitle, $parserOptions );
- $html = $html->mText;
+ $pout = $localParser->parse( $label , $this->mTitle, $parserOptions );
+ $html = $pout->getText();
$ig->add( new Image( $nt ), $html );
$this->mOutput->addImage( $nt->getDBkey() );
* Parse image options text and use it to make an image
*/
function makeImage( &$nt, $options ) {
- global $wgContLang, $wgUseImageResize, $wgUser;
+ global $wgUseImageResize;
$align = '';
}
# Strip bad stuff out of the alt text
$alt = $this->replaceLinkHoldersText( $caption );
+
+ # make sure there are no placeholders in thumbnail attributes
+ # that are later expanded to html- so expand them now and
+ # remove the tags
+ $alt = $this->unstrip($alt, $this->mStripState);
$alt = Sanitizer::stripAllTags( $alt );
# Linker does the rest
}
/**
- * Set a flag in the output object indicating that the content is dynamic and
+ * Set a flag in the output object indicating that the content is dynamic and
* shouldn't be cached.
*/
function disableCache() {
$this->mOutput->mCacheTime = -1;
}
-
- /**
+
+ /**#@+
* Callback from the Sanitizer for expanding items found in HTML attribute
* values, so they can be safely tested and escaped.
* @param string $text
$text = $this->unstripForHTML( $text );
return $text;
}
-
+
function unstripForHTML( $text ) {
$text = $this->unstrip( $text, $this->mStripState );
$text = $this->unstripNoWiki( $text, $this->mStripState );
return $text;
}
+ /**#@-*/
+ /**#@+
+ * Accessor/mutator
+ */
function Title( $x = NULL ) { return wfSetVar( $this->mTitle, $x ); }
function Options( $x = NULL ) { return wfSetVar( $this->mOptions, $x ); }
function OutputType( $x = NULL ) { return wfSetVar( $this->mOutputType, $x ); }
+ /**#@-*/
+
+ /**#@+
+ * Accessor
+ */
+ function getTags() { return array_keys( $this->mTagHooks ); }
+ /**#@-*/
}
/**
$mLanguageLinks, # List of the full text of language links, in the order they appear
$mCategories, # Map of category names to sort keys
$mContainsOldMagic, # Boolean variable indicating if the input contained variables like {{CURRENTDAY}}
- $mCacheTime, # Timestamp on this article, or -1 for uncacheable. Used in ParserCache.
+ $mCacheTime, # Time when this object was generated, or -1 for uncacheable. Used in ParserCache.
$mVersion, # Compatibility check
$mTitleText, # title text of the chosen language variant
$mLinks, # 2-D map of NS/DBK to ID for the links in the document. ID=zero for broken.
$mTemplates, # 2-D map of NS/DBK to ID for the template references. ID=zero for broken.
- $mImages; # DB keys of the images used, in the array key only
+ $mImages, # DB keys of the images used, in the array key only
+ $mExternalLinks; # External link URLs, in the key only
function ParserOutput( $text = '', $languageLinks = array(), $categoryLinks = array(),
$containsOldMagic = false, $titletext = '' )
$this->mLinks = array();
$this->mTemplates = array();
$this->mImages = array();
+ $this->mExternalLinks = array();
}
function getText() { return $this->mText; }
function &getLinks() { return $this->mLinks; }
function &getTemplates() { return $this->mTemplates; }
function &getImages() { return $this->mImages; }
+ function &getExternalLinks() { return $this->mExternalLinks; }
function containsOldMagic() { return $this->mContainsOldMagic; }
function setText( $text ) { return wfSetVar( $this->mText, $text ); }
function addCategory( $c, $sort ) { $this->mCategories[$c] = $sort; }
function addImage( $name ) { $this->mImages[$name] = 1; }
function addLanguageLink( $t ) { $this->mLanguageLinks[] = $t; }
+ function addExternalLink( $url ) { $this->mExternalLinks[$url] = 1; }
- function addLink( $ns, $t, $id ) {
+ function addLink( $title, $id ) {
+ $ns = $title->getNamespace();
+ $dbk = $title->getDBkey();
if ( !isset( $this->mLinks[$ns] ) ) {
$this->mLinks[$ns] = array();
}
- $this->mLinks[$ns][$t] = $id;
+ $this->mLinks[$ns][$dbk] = $id;
}
- function addTemplate( $ns, $t, $id ) {
+ function addTemplate( $title, $id ) {
+ $ns = $title->getNamespace();
+ $dbk = $title->getDBkey();
if ( !isset( $this->mTemplates[$ns] ) ) {
$this->mTemplates[$ns] = array();
}
- $this->mTemplates[$ns][$t] = $id;
+ $this->mTemplates[$ns][$dbk] = $id;
}
/**
var $mEditSection; # Create "edit section" links
var $mNumberHeadings; # Automatically number headings
var $mAllowSpecialInclusion; # Allow inclusion of special pages
+ var $mTidy; # Ask for tidy cleanup
function getUseTeX() { return $this->mUseTeX; }
function getUseDynamicDates() { return $this->mUseDynamicDates; }
function getEditSection() { return $this->mEditSection; }
function getNumberHeadings() { return $this->mNumberHeadings; }
function getAllowSpecialInclusion() { return $this->mAllowSpecialInclusion; }
-
+ function getTidy() { return $this->mTidy; }
function setUseTeX( $x ) { return wfSetVar( $this->mUseTeX, $x ); }
function setUseDynamicDates( $x ) { return wfSetVar( $this->mUseDynamicDates, $x ); }
function setEditSection( $x ) { return wfSetVar( $this->mEditSection, $x ); }
function setNumberHeadings( $x ) { return wfSetVar( $this->mNumberHeadings, $x ); }
function setAllowSpecialInclusion( $x ) { return wfSetVar( $this->mAllowSpecialInclusion, $x ); }
-
+ function setTidy( $x ) { return wfSetVar( $this->mTidy, $x); }
function setSkin( &$x ) { $this->mSkin =& $x; }
function ParserOptions() {
/** Get user options */
function initialiseFromUser( &$userInput ) {
- global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages,
- $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion;
+ global $wgUseTeX, $wgUseDynamicDates, $wgInterwikiMagic, $wgAllowExternalImages;
+ global $wgAllowExternalImagesFrom, $wgAllowSpecialInclusion;
$fname = 'ParserOptions::initialiseFromUser';
wfProfileIn( $fname );
if ( !$userInput ) {
$this->mEditSection = true;
$this->mNumberHeadings = $user->getOption( 'numberheadings' );
$this->mAllowSpecialInclusion = $wgAllowSpecialInclusion;
+ $this->mTidy = false;
wfProfileOut( $fname );
}
}
/**
* Get various statistics from the database
- * @private
+ * @access private
*/
function wfLoadSiteStats() {
global $wgNumberOfArticles, $wgTotalViews, $wgTotalEdits;